package com.whut.service.impl;

import com.whut.mapper.*;
import com.whut.model.Manageinfo;
import com.whut.model.Orderinfo;
import com.whut.model.Userinfo;
import com.whut.service.ManageService;
import com.whut.v_model.AttendInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service("manageService")
public class ManageServiceImp implements ManageService {
    @Resource
    ManageinfoMapper manageinfoMapper;
    @Resource
    UserinfoMapper userinfoMapper;
    @Resource
    RoominfoMapper roominfoMapper;
    @Resource
    OrderinfoMapper orderinfoMapper;
    @Resource
    PostinfoMapper postinfoMapper;

    /*wyh*/
    @Override
    public Object getRegistInfoById(int id, String userName) {
        List<Manageinfo> registList = manageinfoMapper.getRegistInfoById(id, userName);
        List<AttendInfo> attendList = new ArrayList<>();
        for (Manageinfo m: registList) {
            AttendInfo attendInfo = new AttendInfo();
            attendInfo.setUserName(m.getUserName());
            if (m.getRegist().equals(true) && m.getLeave().equals(false)){
                attendInfo.setIsAttend("上班");
                attendInfo.setRegistTime(m.getRegistTime());
            }else if (m.getRegist().equals(false) && m.getLeave().equals(true)){
                attendInfo.setIsAttend("请假");
                attendInfo.setRegistTime(m.getLeaveTime());
            }else if (m.getRegist().equals(false) && m.getLeave().equals(false)){
                attendInfo.setIsAttend("请假驳回");
                attendInfo.setRegistTime(m.getLeaveTime());
            }
            attendList.add(attendInfo);
        }
        return attendList;
    }

    /*wyh*/
    @Override
    public Object getAllLeaveInfoByDate(String date) {
        List<Manageinfo> manageinfoList = manageinfoMapper.getLeaveInfoByDate(date);
        return manageinfoList;
    }

    /*wyh*/
    @Override
    public Object getAllLeaveInfo() {
        List <Manageinfo> manageinfoList = manageinfoMapper.getAllLeaveInfo();
        return manageinfoList;
    }

    /*wyh*/
    @Override
    public Object disagree(int id, String date) {
        int leave = manageinfoMapper.disagreeSetLeave(id, date);
        if(leave == 0){
            return false;
        }
        System.out.println("进行不同意操作");
        List<Manageinfo> manageinfoList = manageinfoMapper.getAllLeaveInfo();
        return manageinfoList;
    }

    /*wyh*/
    @Override
    public Object getRegistInfoByTime(int id, String leaveTime, String startTime, String endTime) {
        List<Manageinfo> registList = manageinfoMapper.getRegistInfoByTime(id, leaveTime, startTime, endTime);
        List<AttendInfo> attendList = new ArrayList<>();
        for (Manageinfo m: registList) {
            AttendInfo attendInfo = new AttendInfo();
            attendInfo.setUserName(m.getUserName());
            if (m.getRegist().equals(true) && m.getLeave().equals(false)){
                attendInfo.setIsAttend("上班");
                attendInfo.setRegistTime(m.getRegistTime());
            }else if (m.getRegist().equals(false) && m.getLeave().equals(true)){
                attendInfo.setIsAttend("请假");
                attendInfo.setRegistTime(m.getLeaveTime());
            }
            attendList.add(attendInfo);
        }
        return attendList;
    }

    @Override
    public String updatePostTypeInfo(String postType, Integer baseSalary, Integer bonus) {
        postinfoMapper.updatePostTypeInfo(postType,baseSalary,bonus);
        return "success";
    }

    @Override
    public Object getSalaryByPostType(String postType) {
        return postinfoMapper.getSalaryByPostType(postType);
    }

    @Override
    public String updatePayById(Integer id, Integer pay) {
        userinfoMapper.updatePayById(id,pay);
        return "success";
    }

    @Override
    public String settlePay(Integer id) {
        userinfoMapper.settlePay(id);
        return "success";
    }


    @Override
    public Userinfo getUserById(int mKey) {
        return userinfoMapper.selectByPrimaryKey(mKey);
    }

    @Override
    public List<Object> getAllUserInfoByMark(Integer mark) {
        return userinfoMapper.getAllUserInfoByMark(mark);
    }

    @Override
    public Orderinfo getOrderById(Integer id) {
        return userinfoMapper.getOrderById(id);
    }

    @Override
    public String deleteUserById(Integer id) {
        userinfoMapper.deleteUserById(id);
        return "success";
    }

    @Override
    public String updateRoomStatusByRoomId(Integer roomId,Integer roomStatus) {
        roominfoMapper.updateRoomStatusByRoomId(roomId,roomStatus);
        return "success";
    }

    @Override
    public String updateUserInfo(Userinfo userinfo) {
        userinfoMapper.updateUserInfo(userinfo);
        return "success";
    }

    @Override
    public String updateOrder(Orderinfo orderinfo) {
        orderinfoMapper.updateOrder(orderinfo);
        return "error";
    }

    @Override
    public Manageinfo getManageInfo(Integer id, Integer registTime) {
        return manageinfoMapper.getManageInfo(id,registTime);
    }

    @Override
    public String updateReason(Integer id, String registTime, String reason) {
        manageinfoMapper.updateReason(id,registTime,reason);
        return "success";
    }

    @Override
    public String deleteManageInfo(Integer id, String registTime) {
        manageinfoMapper.deleteManageInfo(id,registTime);
        return "success";
    }

    @Override
    public String updateManageInfo(Manageinfo mangeinfo) {
        manageinfoMapper.updateManageInfo(mangeinfo);
        return "success";
    }

    @Override
    public String addUserInfo(Userinfo userinfo) {
        userinfoMapper.addUserInfo(userinfo);
        return "success";
    }

    @Override
    public Integer getLeaveTimes(Integer id, Integer registTime) {
        return manageinfoMapper.getLeaveTimes(id,registTime);
    }

    @Override
    public Integer getRegistTimes(Integer id, Integer registTime) {
        return manageinfoMapper.getRegistTimes(id,registTime);
    }

    @Override
    public List<Object> getAllPostInfo() {

        return postinfoMapper.getAllPostInfo();
    }

    @Override
    public Object getAllUserInfo() {
        List<Userinfo> userinfoList  = userinfoMapper.getAllUserInfo2();
        return userinfoList;
    }


}
